package com.yuanqi.repository;

import com.yuanqi.domain.AccountsReceivable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public interface AccountsReceivableRepository extends JpaRepository<AccountsReceivable, Long> {
    
    List<AccountsReceivable> findByCustomerId(Long customerId);
    
    List<AccountsReceivable> findByOverdueStatus(Integer overdueStatus);
    
    @Query("SELECT SUM(ar.invoiceAmount) FROM AccountsReceivable ar WHERE ar.overdueStatus = 1")
    Double getTotalOverdueAmount();
    
    @Query("SELECT SUM(ar.outstandingAmount) FROM AccountsReceivable ar")
    Double getTotalOutstandingAmount();
    
    List<AccountsReceivable> findByDueDateBefore(LocalDate date);
}


